﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--script src方式引入vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!--全局配置，以后只要用vue+axios的页面都引入common.js-->
    <script src="js/common.js"></script>

</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //解析参数上
            let url = location.href;// http://bugtracker.itsource.cn/callback.html?code=051p2m100kZ6GM1ge7100yhviD4p2m1m&state=3
            //  根据url生成对象
            let paramObj = parseUrlParams2Obj(url);
            //   let binderUrl="http://bugtracker.itsource.cn/binder.html";
            //封装请求参数
            let param = {"code":paramObj.code};
            // 发送请求
            this.$http.post("/login/wechat",param)
                .then(result=>{
                    if(result.data.success){
                        // 把用户信心保存到localStorage
                        alert("登录成功");
                        //1.将token和登录信息存入localStorage
                        let {token,logininfo} = result.data.resultObj;
                        localStorage.setItem("token",token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        //2.跳转到首页，并显示登录信息
                        location.href="index.html";
                    } else {
                        let strObj = result.data.resultObj;
                        console.log(strObj)
                        location.href= "binder.html" + strObj;
                    }
                }) .catch(result=>{
                    alert("系统异常，请稍后处理!")
            })
        }
    })

</script>
</body>
</html>